// 4. Controller 层：BlowStatisticsController.java
package com.jdone.compus.controller;

import com.jdone.compus.dto.ApiResponse;
import com.jdone.compus.dto.DeviceSiteStatsDTO;
import com.jdone.compus.service.BlowStatisticsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.LocalDateTime;

@RestController
@RequestMapping("/blow/stats")
@Api(value = "统计设备信息", tags = "统计设备信息")
public class BlowStatisticsController {

    private final BlowStatisticsService statsService;

    public BlowStatisticsController(BlowStatisticsService statsService) {
        this.statsService = statsService;
    }

    @ApiOperation("统计接口--按日期段统计设备总数和终端（IMEI）总数（开始/结束日期可选）")
    @GetMapping("/device-site-stats")
    public ApiResponse stats(
            @RequestParam(value = "start", required = false)
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate start,

            @RequestParam(value = "end", required = false)
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end
    ) {
        DeviceSiteStatsDTO dto = statsService.getDeviceSiteStats(start, end);
        return ApiResponse.success(dto);
    }
}

